package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import dominio.Agente;

public class AgenteDao extends AbstractDao {

	public Collection<Agente> getAgentes () throws SQLException, ClassNotFoundException {
		String sql = "SELECT * from agente";
		PreparedStatement ps = getConnection().prepareStatement(sql);
		ps.execute();
		ResultSet rs = ps.getResultSet();
		
		ArrayList<Agente> agentes = new ArrayList<Agente>();
		
		while(rs.next()) {
			Agente a = new Agente();
			a.setId(rs.getInt("id"));
			a.setNome(rs.getString("nome"));
			a.setSalario(rs.getInt("salario"));
			
			agentes.add(a);
		}
		
		return agentes;
	}
}
